package lee.vioson.ebook.ui

import androidx.activity.viewModels
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.lifecycle.lifecycleScope
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import kotlinx.coroutines.launch
import lee.vioson.ebook.viewmodels.MainAppViewModel
import lee.vioson.remotedata.manager.UserManager

/**
 *Author:viosonlee
 *Date:2023/6/1
 *DESCRIPTION:
 */
class MainActivity : BaseActivity() {
    private val lazyVM: Lazy<MainAppViewModel> = viewModels()
    private val viewModel: MainAppViewModel by lazy { lazyVM.value }

    override fun onStart() {
        super.onStart()
        lifecycleScope.launch{
            UserManager.INSTANCE.init(this@MainActivity)
        }
    }
    @OptIn(ExperimentalAnimationApi::class)
    @Composable
    override fun Content() {
        val navHostController = rememberAnimatedNavController()
        MainApp(viewModel, appContainer, navHostController)
    }

    override fun onStop() {
        super.onStop()
        viewModel.sendEvent(MainAppViewModel.Event.OnExitApp)
    }
}